Skip to content

Conversation

@shwet04
Copy link

@shwet04 shwet04 commented Mar 26, 2025

This PR addresses a stored XSS vulnerability in the Toolbar.php file of the Debug Toolbar system. The issue arises from improper sanitization and validation of the debugbar_time GET parameter, which is used to construct file paths and read their contents. If an attacker injects malicious JavaScript into a debugbar_*.json file, it could be executed when the debug toolbar is accessed, leading to potential security risks.

Issue Details:
Vulnerability:

The debugbar_time parameter was not properly validated, allowing attackers to inject malicious payloads. The file contents were directly echoed back to the client without escaping, enabling stored XSS attacks.

Impact:

  1. Session Hijacking: Attackers could steal session cookies of admins or users.
  2. Persistent Malware Injection: Malicious scripts could persist in the debug logs and execute whenever accessed.
  3. Privilege Escalation: If executed in a privileged session, attackers could perform unauthorized actions.

Fix Implemented:
1 . Input Validation: Added a preg_match() check to ensure the debugbar_time parameter only contains alphanumeric characters and underscores (^[a-zA-Z0-9_]+$). This prevents malicious input from being used to construct file paths.

  1. Output Escaping: Used htmlspecialchars() to escape special characters (<, >, ", ', &) in the file contents before echoing them back to the client. This ensures that any potentially malicious content is rendered harmless in the browser.

  2. File Existence and Readability Check:Added a check to ensure the file exists and is readable (is_file() and is_readable()) before attempting to read its contents.

Please review and merge this PR to address the security vulnerability.

…r)!!

This PR addresses a stored XSS vulnerability in the Toolbar.php file of the Debug Toolbar system. The issue arises from improper sanitization and validation of the debugbar_time GET parameter, which is used to construct file paths and read their contents. If an attacker injects malicious JavaScript into a debugbar_*.json file, it could be executed when the debug toolbar is accessed, leading to potential security risks.

Issue Details:
Vulnerability:

The debugbar_time parameter was not properly validated, allowing attackers to inject malicious payloads.
The file contents were directly echoed back to the client without escaping, enabling stored XSS attacks.
Impact:

Session Hijacking: Attackers could steal session cookies of admins or users.
Persistent Malware Injection: Malicious scripts could persist in the debug logs and execute whenever accessed.
Privilege Escalation: If executed in a privileged session, attackers could perform unauthorized actions.

Fix Implemented:
1 . Input Validation: Added a preg_match() check to ensure the debugbar_time parameter only contains alphanumeric characters and underscores (^[a-zA-Z0-9_]+$).
This prevents malicious input from being used to construct file paths.

2. Output Escaping: Used htmlspecialchars() to escape special characters (<, >, ", ', &) in the file contents before echoing them back to the client.
This ensures that any potentially malicious content is rendered harmless in the browser.

3. File Existence and Readability Check:Added a check to ensure the file exists and is readable (is_file() and is_readable()) before attempting to read its contents.

Please review and merge this PR to address the security vulnerability.
@mergeable
Copy link

mergeable bot commented Mar 26, 2025

Hi there, shwet04! 👋

Thank you for sending this PR!

We expect the following in all Pull Requests (PRs).

Important

We expect all code changes or bug-fixes to be accompanied by one or more tests added to our test suite to prove the code works.

If pull requests do not comply with the above, they will likely be closed. Since we are a team of volunteers, we don't have any more time to work
on the framework than you do. Please make it as painless for your contributions to be included as possible.

See https://github.com/codeigniter4/CodeIgniter4/blob/develop/contributing/pull_request.md

Sincerely, the mergeable bot 🤖

@shwet04 shwet04 changed the title Fix Stored XSS Vulnerability in Debug Toolbar (debugbar_time Paramete… fix::Stored XSS Vulnerability in Debug Toolbar (debugbar_time Paramete… Mar 26, 2025
@shwet04 shwet04 changed the title fix::Stored XSS Vulnerability in Debug Toolbar (debugbar_time Paramete… fix: Stored XSS Vulnerability in Debug Toolbar (debugbar_time Paramete… Mar 26, 2025
@neznaika0
Copy link
Contributor

You will be asked to delete the pr and contact by email if this is a serious problem.
https://github.com/codeigniter4/CodeIgniter4/security

@shwet04
Copy link
Author

shwet04 commented Mar 26, 2025

Hello @neznaika0 ,

I have shared an email -- The suggest for me was to generate a fix !!

@lonnieezell
Copy link
Member

Yes, they sent the report to the appropriate channels. Since this was a debug tool that doesn't work in production, it was deemed not as high an impact as it would otherwise be. I think I do have another report from them I need to share still, though....

@lonnieezell
Copy link
Member

The PR looks like a good fix, but will need one of us to pull it down and test it out to ensure the toolbar still works. It might be a couple of days before I can get to it.

Copy link
Member

@michalsn michalsn left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The current changes break the debug toolbar. Please make fixes based on my comments.

You can also use composer cs-fix to improve the code style.

@shwet04
Copy link
Author

shwet04 commented Mar 27, 2025

@michalsn ,

I made the requested changes !! Assuming that debugbar_time considers timestamp and would allow numeric values with an optional decimal point. Can you confirm the expected format of debugbar_time (e.g., alphanumeric, timestamp, or other) ???

@michalsn
Copy link
Member

@shwet04 Thank you.

The format is always the same: timestamp.milliseconds (so the decimal point is not optional). You have a ready to use regex in the format() method.

@shwet04
Copy link
Author

shwet04 commented Mar 27, 2025

@michalsn , Can you review it now ?? Is everything okay ??

@michalsn
Copy link
Member

@shwet04 No, it's not - sorry.

At first, I didn't pay attention to what data exactly you are trying to use with the htmlspecialchars function, but now I see that it doesn't make much sense because we won't be able to display data in any format properly.

Then I realized that we are using a Parser to generate the Toolbar, so all data should be automatically escaped in HTML format. When it comes to other formats, I think it's up to the developer to handle this.

Can you provide us with a working example of this vulnerability that would display, for example, an alert('XSS') or something equally simple?

At this point, I don't think this bug report is valid.

@shwet04
Copy link
Author

shwet04 commented Mar 27, 2025

Screenshot 2025-03-27 at 7 05 16 PM

@michalsn
Copy link
Member

I was referring to the htmlspecialchars part.

@shwet04
Copy link
Author

shwet04 commented Mar 27, 2025

After further testing, I have not been able to generate a working XSS PoC. It appears that the application properly escapes user input before rendering. I appreciate your time reviewing this report. If I find new evidence of an issue, I will follow up with additional details. Thanks!

@michalsn Can you please take time to review other findings that I have shared over Email.

@michalsn
Copy link
Member

@shwet04, I do not know of any additional issues, but please don't share any possible vulnerabilities publicly. @lonnieezell mentioned something in one of his previous posts here, but I believe he will have to evaluate it first

If that's it for now, feel free to close this PR.

@michalsn
Copy link
Member

@shwet04 We have carefully analyzed the findings sent to us, and none of them represent a real vulnerability.

  • All parameters that use mt_rand() in the random_string helper are deprecated because they are not cryptographically secure. We inform about it in the code as well as in the user guide.
  • Replacing dynamicScript.innerHTML in the debug toolbar is also safe as there is no way to manipulate the responseText. If that were possible, the vulnerability would be valid for almost any AJAX request - not only for the Toolbar. Also, the Toolbar is not meant to be used in the production environment.

Anyway, thank you for your report and for trying to make CodeIgniter more secure.

@michalsn michalsn closed this Mar 28, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants